package com.tianyi.sfzy1.controller;

import com.tianyi.sfzy1.domain.Consultationappointment;
import com.tianyi.sfzy1.service.ConsultationappointmentService;
import com.tianyi.sfzy1.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/consultationappointment")
public class ConsultationappointmentController {
    @Autowired
    private ConsultationappointmentService consultationappointmentService;
    @PutMapping
    public R updateFinishStatus(Integer appointmentId, Integer finishStatus){
        if (appointmentId == null || finishStatus == null) {
            return R.error("appointmentId 和 finishStatus 不能为空");
        }
        return R.ok(consultationappointmentService.updateFinishStatus(appointmentId, finishStatus));
    }

    @PostMapping
    public R insertConsultationappointment(@RequestBody Consultationappointment consultationappointment){
        System.out.println(consultationappointment);
        if (consultationappointment == null) {
            return R.error("参数不能为空");
        }
        return R.ok(consultationappointmentService.insertConsultationappointment(consultationappointment));
    }

    /**
     * 根据用户id和咨询状态查询咨询记录
     */
    @GetMapping
    public R findAll(int memberId,int status){
        System.out.println(memberId);
        System.out.println(status);
        List<Consultationappointment> list=consultationappointmentService.findAll(memberId,status);
        return R.ok(list);
    }

    /**
     * 根据咨询id删除咨询记录
     */
    @DeleteMapping
    public R delete(int id){
        System.out.println(id);
        int i= consultationappointmentService.delete(id);
        if (i>0){
            return R.ok(null);
        }else {
            return R.fail("删除失败");
        }
    }

}
